﻿@using ETD.Common.Extension;
@using ETD.WebManagement.Libs.Helper;
@using ETD.WinClient.Config;
@using ETD.Domain.EnumModels;
@using ETD.Domain.WebModels;
@using ETD.Common;
@using ETD.WebManagement.Libs.Controls;
@model ETD.WebManagement.Areas.Web.Models.BindAccountModel
@{
    ViewBag.Title = "绑定账号";
}
@{
//var securityCheckItemList = Model.SecurityCheckItemList.Where(x => x.CheckResultStatusID == (int)ECheckResultStatus.WaitCheck).ToList();
//var securityCheckItemQualifiedList = Model.SecurityCheckItemList.Where(x => x.CheckResultStatusID == (int)ECheckResultStatus.Qualified).ToList();
//var securityCheckItemUnqualifiedList = Model.SecurityCheckItemList.Where(x => x.CheckResultStatusID == (int)ECheckResultStatus.Unqualified).ToList();
}
<style>
    .weui-select {
        padding-left: 0px !important;
    }
</style>
<div class="weui-cells__title">绑定新账号</div>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">手机号</label></div>
        <div class="weui-cell__bd">
            <input id="txtMobile" class="weui-input" type="number" pattern="[0-9]*" maxlength="11" placeholder="请输入手机号">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
        <div class="weui-cell__bd">
            <input id="txtRealName" class="weui-input" type="text" placeholder="请输入姓名" maxlength="10">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">岗位</label></div>
        <div class="weui-cell__bd">
            @ETDSelectCtl.New().BindID("ddlDepartment").BindData(Model.DepartmentList).BindSelected("").Render()
        </div>
    </div>
    <div class="weui-btn-area">
        <a class="weui-btn weui-btn_primary" href="javascript:" id="btnBind">确定</a>
    </div>
</div>
@section ScriptSection{
    <script>
        $(function () {
            $("#btnBind").click(onBtnBindClick);
        });

        function isPhoneAvailable(poneInput) {
            var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
            if (!myreg.test(poneInput)) {
                return false;
            } else {
                return true;
            }
        }
        function isNullOrEmpty(str) {
            if (str == null) return true;
            if (str.trim() == "") return true;
            return false;
        }
        function isVaildEntityID(str) {
            if (isNullOrEmpty(str)) return false;
            if (str > 0) {
                return true;
            }
            return false;
        }

        function onBtnBindClick() {
            var checkFormResult = checkForm();
            if (!checkFormResult) return;
            confirmBindAccount(bindAccount);
        }
        function checkForm() {
            var mobile = $("#txtMobile").val();
            if (!isPhoneAvailable(mobile)) {
                $.toptip('请输入合法手机号', 'warning');
                return false;
            }
            var realName = $("#txtRealName").val();
            if (isNullOrEmpty(realName)) {
                $.toptip('请输入姓名', 'warning');
                return false;
            }

            var departmentValue = $('#ddlDepartment').val();
            if (!isVaildEntityID(departmentValue)) {
                $.toptip('请选择部门', 'warning');
                return false;
            }
            return true;
        }
        function confirmBindAccount(callback) {
            $.confirm("确定绑定此信息吗?", "确认?", function () {
                callback();
            }, function () {
                //取消操作
            });
        }
        function bindAccount() {
            var paras = {};
            paras.Mobile = $("#txtMobile").val().trim();
            paras.RealName = $("#txtRealName").val().trim();
            paras.DepartmentID = $("#ddlDepartment").val().trim();
            console.log(JSON.stringify(paras));

            ajaxPost("@Url.Action("BindAccountInfo", "Account")", paras, function (data) {
                console.log(data);
                if (data.Status) {
                    $.toast(data.Info);
                    window.setTimeout(function () { window.location.href = "@Url.Action("TodayTask", "Security")"; }, 2000);
                } else {
                    $.toast(data.Info, "forbidden");
                    window.setTimeout(function () { window.location.href = "@Url.Action("TodayTask", "Security")"; }, 2000);
                }
            });
        }
        @*function checkUnqualified(callBack) {
            var paras = {};
            paras.SecurityCheckItemID = @securityCheckItem.SecurityCheckItemID;
            paras.CheckResultInfo = $("#txtCheckResultInfo").val();

            if(!paras.CheckResultInfo.trim()){
                $.toptip('检查不合格必须填写结果', 'warning');
                return;
            }

            ajaxPost("@Url.Action("CheckUnqualified", "Lianmeng")", paras, function (data) {
                console.log(data);
                if (data.Status) {
                    $.toast("操作完成!");
                    callBack();
                } else {

                }
            });
        }*@
    </script>
}